package base

import (
	"jvm/rtda"
	. "jvm/typedef"
)

type Inst interface {
	ReadOperands(reader *CodeReader)
	Execute(frame *rtda.Frame)
}

// ****************************************************************
// 无操作数指令
type NoOperandsInst struct {
}

func (self *NoOperandsInst) ReadOperands(reader *CodeReader) {

}

// ****************************************************************
// 操作数为U1的索引的指令
type U1IndexInst struct {
	Index U2
}

func (self *U1IndexInst) ReadOperands(reader *CodeReader) {
	self.Index = U2(reader.ReadU1())
}

// ****************************************************************
// 分支指令
type BranchInst struct {
	offset I2
}

func (self *BranchInst) ReadOperands(reader *CodeReader) {
	self.offset = reader.ReadI2()
}
func (self *BranchInst) SetBranchPC(frame *rtda.Frame) {
	pc := I8(frame.Thread().PC())
	offset := I8(self.offset)
	addr := pc + offset
	frame.SetNextPC(U4(addr))
}
